<style lang="less">
@import "./supplierDis.less";
</style>
<template>
    <div class="search">
      <Row class="margin-top-10 searchable-table-con1">
          <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
          <Table :columns="columns" :data="exportData" ref="exportTable" style="display:none"></Table>
      </Row>
      <!-- <Row type="flex" justify="end" class="code-row-bg page">
          <Page :current="this.searchForm.pageNumber" :total="total" :page-size="this.searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50,100]" size="small" show-total show-elevator show-sizer></Page>
      </Row> -->
    </div>
</template>

<script>

export default {
  name: "self-view",
  props:{
    supplierId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      drop: false,
      selectCount: 0,
      selectList: [],
      searchForm: {
        supplierId: "",
        pageNumber: 1,
        pageSize: 10,
        sort: "createTime",
        order: "desc"
      },
      modalType: 0,
      lineModalVisible: false,
      modalTitle: "",
      lineForm: {
        sex: 1,
        type: 0
      },
      userRoles: [],
      roleList: [],
      errorPass: "",
      lineFormValidate: {
      },
      submitLoading: false,
      columns: [
        {
          type: "selection",
          width: 60,
          align: "center"
        },
        {
          title: "商户名称",
          key: "supplierName",
          width: 220,
          sortable: true
        },
        {
          title: "商品名称",
          key: "name",
          width: 200,
          sortable: true
        },
        {
          title: "商品价格",
          key: "price",
          align: "center",
          width: 200
        },
        {
          title: "是否分销",
          key: "isDistribut",
          align: "center",
          width: 200
        },
        {
          title: "分销商品类型",
          key: "type",
          width: 200,
          align: "center",
          render: (h, params) => {
            let re = "";
            if (params.row.type === 1) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      // type: "dot",
                      color: "yellow"
                    }
                  },
                  "线路"
                )
              ]);
            } else if (params.row.type === 2) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      color: "green"
                    }
                  },
                  "客栈"
                )
              ]);
            } else if (params.row.type === 3) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      color: "red"
                    }
                  },
                  "特产"
                )
              ]);
            } else if (params.row.type === 4) {
              return h("div", [
                h(
                  "Tag",
                  {
                    props: {
                      color: "green"
                    }
                  },
                  "通用商品"
                )
              ]);
            }
          },
        }
      ],
      data: [],
      exportData: [],
      total: 0

      ,
      lineReviewModalVisible: false,
      lineReviewForm: {
        reviewLineId: "",
        reviewStatus: "0",
        nopassReason: "",
        nopassReasonVisible: false
      },
      currSupplierId: '',
      currSupplierName: '',
      lineReviewFormValidate: {
      },

    };
  },
  methods: {
    transSupplierId(supplierId){
      this.searchForm.supplierId = supplierId;
      this.currSupplierId = supplierId;
      this.getlineList();
    },


    init() {
      console.log("==============");
      console.log(this.supplierId);
      this.getlineList();
      this.cleanSelectCount();
    },
    initData(value){
      console.log("===========value========");
      console.log(value);
      this.getlineList();
    },
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getlineList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getlineList();
    },

    getlineList() {
      this.loading = true;
      // this.getRequest("/distribut_goods/list", this.searchForm).then(res => {
      this.getRequest("/supplier/getMap",{id: this.currSupplierId}).then(res => {
        this.loading = false;
        if (res.success === true) {
          // this.data = res.result;
          console.log(res.result);
          this.data = this.praseMapResult(res.result);
          // this.total = res.result.totalElements;
        }
      });
    },

    praseMapResult(supplierData){
      if(supplierData){
        var _this = this;

        let hotelList = supplierData.hotelList;
        let lineList = supplierData.lineList;
        let goodsList = supplierData.goodsList;
        let goodsItemList = supplierData.goodsItemList;

        this.supplierName = supplierData.supplier.supplierName;

        var returnData = [];

        lineList.forEach(function(item){
          returnData.push({
            supplierName: _this.supplierName,
            name: item.title,
            price: item.storePrice,
            isDistribut: item.isDistribut,
            type: 1
          })
        })

        hotelList.forEach(function(item){
          returnData.push({
            supplierName: _this.supplierName,
            name: item.title,
            price: item.price,
            isDistribut: item.isDistribut,
            type: 2
          })
        })

        goodsList.forEach(function(item){
          returnData.push({
            supplierName: _this.supplierName,
            name: item.goodsName,
            price: item.marketPrice,
            isDistribut: item.isDistribut,
            type: 3
          })
        })

        goodsItemList.forEach(function(item){
          returnData.push({
            supplierName: _this.supplierName,
            name: item.itemName,
            price: item.itemPrice,
            isDistribut: item.isDistribut,
            type: 4
          })
        })

        return returnData;
      }
    },

    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order === "normal") {
        this.searchForm.order = "";
      }
      this.init();
    },

    lineRevewStatusChange(value) {
      (value === "-1") ? (this.lineReviewForm.nopassReasonVisible = true) : (this.lineReviewForm.nopassReasonVisible = false);
    },
    cancelLineReview() {
      this.lineReviewModalVisible = false;
    },
    submitLineReview() {
      let url = "";
      url = "/line/review";
    },

    openDistribute(v) {
      if(v.id){
        let returnDisObj = {
          flag: true,
          type: "LINE",
          disObj: v
        }
        this.$emit('on-open-success',returnDisObj);
      }
    },

    closeDistribute(v) {
      if(v.id){
        let returnDisObj = {
          flag: true,
          type: "LINE",
          disObj: v
        }
        this.$emit('on-close-success',returnDisObj);
      }
    },

    disPercentSet(v){
      if(v.id){
        let returnDisObj = {
          flag: true,
          type: "LINE",
          disObj: v
        }
        this.$emit('on-percentset-success',returnDisObj);
      }
    },

    showSelect(e) {
      this.exportData = e;
      this.selectList = e;
      this.selectCount = e.length;
    },
    clearSelectAll() {
      this.$refs.table.selectAll(false);
      this.cleanSelectCount();
    },
    cleanSelectCount(){
      this.selectCount = 0;
    }
  },
  mounted() {
    // this.init();
  }
};
</script>
